﻿@{
    ViewBag.Title = "人员搜索";
    Layout = "~/Views/Shared/PlanPartial/_LayoutSearch.cshtml";
}
<style type="text/css">
    .parameter { width: 300px; display: inline-block; *display: inline; *zoom: 1; }
</style>

@using Wicresoft.UnifyShow.Business
@{
    var IsGlobalConfigAdmin = (bool)ViewBag.IsGlobalConfigAdmin;
    var GlobalCompanyName = ViewData["GlobalCompanyName"] as string;
    var currentCompany = ViewData["CurrentCompany"] as string;
    var site = ViewData["Sites"] as List<string>;
    var isNotSingle = (bool)ViewData["isNotSingle"];
}
<div class="parameter">
    <div class="parameter_name" style="width: 45px;">姓名：</div>
    <div class="parameter_input" style="width: 245px;">
        <input type="text" style="width: 84%;" id="Name" />
    </div>
</div>
@if (IsGlobalConfigAdmin)
{
    <div class="parameter">
        <div class="parameter_name" style="width: 45px;">单位：</div>
        <div class="parameter_input" style="width: 245px;">
            <select style="width: 85%;" onchange="companyselect()" id="Company">
                <option value="">所有</option>
                @foreach (var item in site)
                {
                    //默认选中省局
                    <option value="@(item)" @(string.Equals(item, GlobalCompanyName) ? "selected='selected'" : "")>@(item)</option>
                }
            </select>
        </div>
    </div>
}
else
{
    //不是省局管理员是Company就是当前用户自己所在的单位
    <input type="hidden" value="@(currentCompany)" id="Company" />
}
<div class="parameter">
    <div class="parameter_name" style="width: 45px;">部门：</div>
    <div class="parameter_input" style="width: 245px;">
        <select style="width: 85%;" id="Department">
        </select>
    </div>
</div>
<div class="parameter">
    <input type="button" value="搜索" onclick="startSearch();" />
</div>
<div style="padding: 10px 0;">
    <table id="ResponsibleList" class="" title="人员信息" style="height:335px;"
        fitcolumns="true" singleselect="@(isNotSingle ? "false" : "true")" pagination="true">
        <thead>
            <tr>
                <th data-options="field:'ck',checkbox:true"></th>
                @if (IsGlobalConfigAdmin)
                {
                    <th field="Company" width="120" sortable="true">单位</th>
                }
                <th field="Department" width="120" sortable="true">部门</th>
                <th field="DisplayName" sortable="true">姓名</th>
                <th field="ID"></th>
                <th field="Position" width="120" sortable="true">职务</th>
            </tr>
        </thead>
    </table>
</div>

<script type="text/javascript">
    var AddRow = function () {
        var selected = $('#ResponsibleList').datagrid('getSelections'),
            parenter = GetParentWindow();

        if (parenter && selected.length) {
            parenter.addResponsible(selected);
            closeWindow();
        }
    };

    //依据单位获取部门
    var companyselect = function (callback) {
        $('#Department').empty();
        var rnd = (new Date()).getMilliseconds() + "" + parseInt(Math.random() * 10000);
        var company = $('#Company').val();

        var url = "/PlanManagement/GetDepartment?company=" + encodeURI(company) + "&nocatch=" + rnd;
        $.getJSON(url, function (data) {
            $('#Department').append('<option value="">所有</option>');
            $.each(data, function (i, item) {
                $('#Department').append($("<option></option>").val(item).html(item));
            });

            if (company == "") { $('#Department').val('').attr('disabled', true); }
            else { $('#Department').removeAttr('disabled'); }

            if (callback && typeof callback == "function") {
                callback();
            }
        });
    };

    //开始搜索
    var startSearch = function () {
        var query = {
            Name: $('#Name').val(),
            Company: $('#Company').val(),
            Department: $('#Department').val()
        };

        $('#ResponsibleList').datagrid('load', query);

    };

    $(function () {

        companyselect(function () {

            var query = {
                Name: $('#Name').val(),
                Company: $('#Company').val(),
                Department: $('#Department').val()
            };

            $('#ResponsibleList').datagrid({
                url: '/PlanManagement/SerachResult',
                pageList: [10],
                pageSize: 10,
                pageNumber: 1,
                queryParams: query
            });

            $('#ResponsibleList').datagrid('hideColumn', 'ID');
            var p2 = $('#ResponsibleList').datagrid('getPager');
            $(p2).pagination({
                beforePageText: '第',
                afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
                displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

            });

        });

    });
</script>

